package cn.gok.mybatisplus22.controller;

import cn.gok.mybatisplus22.entity.Student;
import cn.gok.mybatisplus22.mapper.ClazzMapper;
import cn.gok.mybatisplus22.service.StudentService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName StudentController
 * @Description TODO
 * @Author HP
 * @Date 11:22 2022/7/22
 * @Version 1.0
 **/
@RestController
@RequestMapping("/student")
public class StudentController {
    @Autowired

    private StudentService studentService;
    //查询所有学生
    @RequestMapping("/findAll")
    public List<Student> findAllStudent() {
        return studentService.list(null);
    }
    //根据id来查询学生信息
    @RequestMapping("/findById")
    public Student findStudentById(@RequestParam long id){
        return studentService.getById(id);
    }
    //模糊查询学生信息
    @RequestMapping("/select")
    public List<Student>  selectStudent(Student student){
        QueryWrapper<Student> wrapper = new QueryWrapper<>();
        wrapper.like("sname",student.getSname());
        return  studentService.list(wrapper);
    }
    //分页查询学生信息
    @RequestMapping("/selectPage")
    public IPage<Student> selectPage(@RequestParam int cur, @RequestParam int size){
        Page<Student> page=new Page<>(cur,size);


        return  studentService.page(page,null);

    }
    //添加学生信息
    @RequestMapping("/save")
    public boolean saveStudent(@RequestBody Student student) {
        return studentService.save(student);
    }

    //修改学生信息
    @RequestMapping("/update")
    public boolean updateStudentById(@RequestBody Student student) {
        return studentService.updateById(student);
    }
    //根据id删除学生信息
    @RequestMapping("/removeById")
    public boolean removeStudentById(@RequestParam Long id) {
        //返回Boolean类型
        return studentService.removeById(id);
    }
    //批量删除学生信息
    @RequestMapping("/removeByIds")
    public boolean removeStudentByIds(@RequestBody List<Integer> ids) {
        return studentService.removeByIds(ids);
    }





}
